<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/lk.css"/>
    <title>博客管理</title>
</head>
<body>
<!--导航-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment lk-padded-tb-mini">
    <div class="ui container">
<!--        stackable可堆叠的-->
        <div class="ui inverted stackable secondary menu">
            <h2 class="ui teal header item">管理后台</h2>
            <a href="#" class="item lk-item lk-mobile-hide"><i class=" home icon"></i> 博客</a>
            <a href="#" class="item lk-item lk-mobile-hide"><i class=" idea icon"></i> 分类</a>
            <a href="#" class="item lk-item lk-mobile-hide"><i class=" tag icon"></i>标签</a>
            <div class="right item lk-item lk-mobile-hide menu">
                <div class="ui dropdown item">
                    <div class="text">
                        <img src="https://picsum.photos/id/1004/100/100" alt="" class="ui avatar image">张三丰
                        <i class="dropdown icon"></i>
                    </div>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
<!--    导航小图标-->
    <a href="#" class="ui black icon button lk-right-top lk-mobile-show menu toggle">
        <i class="sidebar icon"></i>
    </a>
</nav>
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" th:href="@{/admin/blogs/input}" class=" item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="teal active item">列表</a>
        </div>
    </div>
</div>
<!--中间部分-->
<div class="lk-container-small">
    <br>
    <br>
    <br>
    <br>
    <div class="ui container">
        <div  class="ui secondary segment form">
<!--            隐藏域，用来传递page分页对象-->
            <input type="hidden" name="page" >
            <div class="inline fields">
                <div class="field">
                    <input type="text" id="title" name="title" placeholder="标题">
                    <label for="title"></label>
                    <div class="ui type selection dropdown">
                        <input type="hidden" name="type">
                        <i class="default text">分类</i>
                        <div class="menu">
                            <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
<!--                            使用原型注释块-->
<!--                            /*-->
                            <div class="item" data-value="2">学习手册</div>
<!--                            */-->
                        </div>
                    </div>
                    <button id="clear-btn" class="ui compact button">clear</button>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button  id="search-btn" class="ui basic teal button">
                        <i class="search icon"></i>
                        搜索</button>
                </div>
            </div>
        </div>
        <div id="table-container">
        <table th:fragment="blogList" class="ui table">
            <thead>
            <tr>
                <th></th>
                <th>标题</th>
                <th>类型</th>
                <th>推荐</th>
                <th>状态</th>
                <th>更新时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="blog,iterStat : ${page.content}">
                <td th:text="${iterStat.count}"> 1</td>
                <td th:text="${blog.title}">我爱学习</td>
                <td th:text="${blog.type.name}">学习</td>
                <td th:text="${blog.recommend} ? '是':'否'">是</td>
                <td th:text="${blog.published} ? '发布':'草稿'">草稿</td>
                <td th:text="${blog.updateTime}">2020-12-12</td>
                <td>
                    <a href="#"  th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini basic teal button">编辑</a>
                    <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui mini basic red button">删除</a>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="6">
                    <div class="ui pagination menu" th:if="${page.totalPages}>1">
                        <a onclick="page(this)" th:attr="data-page=${page.number}-1" href="#" class="item " th:unless="${page.first}">上一页</a>
                        <a onclick="page(this)" th:attr="data-page=${page.number}+1" href="#" class="item " th:unless="${page.last}">下一页</a>
                    </div>
                    <a href="" th:href="@{/admin/blogs/input}" class="ui mini right floated basic teal button">新增</a>
                </td>
            </tr>
            </tfoot>
        </table>
<!--            提示框-->
            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${message}">恭喜，操作成功！</p>
            </div>
        </div>
        <br>
        <br>
        <br>
    </div>
    </div>

<!--底部-->
<footer th:fragment="footer" class="ui stackable inverted vertical segment ">
<div class="ui stackable center aligned container lk-padded-tb">
    <div class="ui  stackable inverted divided grid">
        <div class="three wide column">
            <img src="../../static/images/这是一个网上的二维码.jpg" alt="二维码图片" style="width: 10em;height: 10em">
        </div>
        <div class="three wide column">
            <h4 class="ui inverted header">最新博客</h4>
            <div class="ui inverted link list">
                <a href="#" class="item">用户故事</a>
                <a href="#" class="item">用户故事</a>
                <a href="#" class="item">用户故事</a>
            </div>
        </div>
        <div class="three wide column">
            <h4 class="ui inverted header">最新博客</h4>
            <div class="ui inverted link list">
                <a href="#" class="item">用户故事</a>
                <a href="#" class="item">用户故事</a>
                <a href="#" class="item">用户故事</a>
            </div>
        </div>
        <div class="seven wide column">
            <h4 class="ui inverted header">最新博客</h4>
            <p>这是我的个人博客</p>
        </div>
    </div>
    <div class="ui inverted section divider">    </div>
    <p class="lk-text-thin lk-text-space lk-opacity-tiny" style="align-content: center"> Copyright © 2020 - 2021 LKBS Designed by LKBS</p>
</div>

</footer>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script>
    $(".menu.toggle").click(function (){
        $(".lk-item").toggleClass('lk-mobile-show');
    })
    //二维码弹窗
    $('#payButton').popup({
        popup:$('.payQR.popup'),
        on:'click',
        position:'bottom center'
    });
    //下拉组件初始化
    $('.ui.dropdown').dropdown({
        on: "hover"}
    );
    //分页page对象
    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loaddata();
    }
    function loaddata() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
            title : $("[name='title']").val(),
            typeId : $("[name='typeId']").val(),
            recommend : $("[name='recommend']").prop('checked'),
            page : $("[name='page']").val()
        });
    }
    //为按钮绑定点击事件
    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loaddata();
    });
    //分类清除按钮
    $('#clear-btn')
        .on('click', function() {
            $('.ui.type.dropdown')
                .dropdown('clear');
        });
</script>
</body>

</html>